package com.shop2cn.iapi.subscription.testcase;

import org.junit.After;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.subscription.parameter.*;
import com.shop2cn.iapi.subscription.service.*;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodmchSubscriptionService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*查询订单缴费记录Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetSubscriptionChargeList{
	private static GetSubscriptionChargeListBean getsubscriptionchargelistBean;
	private static GetSubscriptionChargeListCall getsubscriptionchargelistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询订单缴费记录Test");
	}

	@Before
	public void caseUp() {
		getsubscriptionchargelistBean=new GetSubscriptionChargeListBean();
		getsubscriptionchargelistCall=new GetSubscriptionChargeListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getsubscriptionchargelistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSubscriptionChargeList_001() {
		Logger.start(true,"付费一年，通过商户id查询交费记录，成功");
		try {
			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			//创建付费订单
			GodmchSubscriptionService.ApplyCharge(mchId,0,3);
			//付费订单回调通知
			GodmchSubscriptionService.ChargeNotify(mchId);
			getsubscriptionchargelistBean.setMchId(mchId);
			getsubscriptionchargelistBean.setPageIndex(1);
			getsubscriptionchargelistBean.setPageSize(100);
			getsubscriptionchargelistCall.setData(getsubscriptionchargelistBean);
			getsubscriptionchargelistCall.callService();			
			Logger.verifyEquals("200", getsubscriptionchargelistCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getsubscriptionchargelistCall.getJsonObject().getAsJsonObject("data").get("total").getAsInt(), "验证获取数量");
			JsonObject ChargeList = getsubscriptionchargelistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("subscriptionChargeList").get(0).getAsJsonObject();
			Logger.verifyEquals(3,ChargeList.get("funcPackageId").getAsInt(),"验证funcPackageId");
			Logger.verifyEquals(mchId,ChargeList.get("mchId").getAsInt(),"验证mchId");
			Logger.verifyEquals(0,ChargeList.get("funcType").getAsInt(),"验证funcType");
			Logger.verifyEquals("直播",ChargeList.get("funcTypeValue").getAsString(),"验证funcTypeValue");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSubscriptionChargeList_002() {
		Logger.start(true,"申请试用一月，通过商户id查询交费记录，成功");
		try {
			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			//申请试用一月
			GodmchSubscriptionService.applyTryout(mchId,0,1);
			getsubscriptionchargelistBean.setMchId(mchId);
			getsubscriptionchargelistBean.setPageIndex(1);
			getsubscriptionchargelistBean.setPageSize(100);
			getsubscriptionchargelistCall.setData(getsubscriptionchargelistBean);
			getsubscriptionchargelistCall.callService();			
			Logger.verifyEquals("200", getsubscriptionchargelistCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getsubscriptionchargelistCall.getJsonObject().getAsJsonObject("data").get("total").getAsInt(), "验证获取数量");
			JsonObject ChargeList = getsubscriptionchargelistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("subscriptionChargeList").get(0).getAsJsonObject();
			Logger.verifyEquals(1,ChargeList.get("funcPackageId").getAsInt(),"验证funcPackageId");
			Logger.verifyEquals(mchId,ChargeList.get("mchId").getAsInt(),"验证mchId");
			Logger.verifyEquals(0,ChargeList.get("funcType").getAsInt(),"验证funcType");
			Logger.verifyEquals("直播",ChargeList.get("funcTypeValue").getAsString(),"验证funcTypeValue");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSubscriptionChargeList_003() {
		Logger.start(true,"申请试用一月，再付费一年。通过商户id查询交费记录，成功");
		try {
			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			//申请试用一月
			GodmchSubscriptionService.applyTryout(mchId,0,1);
			Thread.sleep(1000);
			//创建付费订单
			GodmchSubscriptionService.ApplyCharge(mchId,0,3);
			//付费订单回调通知
			GodmchSubscriptionService.ChargeNotify(mchId);
			getsubscriptionchargelistBean.setMchId(mchId);
			getsubscriptionchargelistBean.setPageIndex(1);
			getsubscriptionchargelistBean.setPageSize(100);
			getsubscriptionchargelistCall.setData(getsubscriptionchargelistBean);
			getsubscriptionchargelistCall.callService();			
			Logger.verifyEquals("200", getsubscriptionchargelistCall.getString("code"), "验证code");
			Logger.verifyEquals(2, getsubscriptionchargelistCall.getJsonObject().getAsJsonObject("data").get("total").getAsInt(), "验证获取数量");
			
			JsonObject ChargeList = getsubscriptionchargelistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("subscriptionChargeList").get(0).getAsJsonObject();
			Logger.verifyEquals(3,ChargeList.get("funcPackageId").getAsInt(),"验证funcPackageId");
			Logger.verifyEquals(mchId,ChargeList.get("mchId").getAsInt(),"验证mchId");
			Logger.verifyEquals(0,ChargeList.get("funcType").getAsInt(),"验证funcType");
			Logger.verifyEquals("直播",ChargeList.get("funcTypeValue").getAsString(),"验证funcTypeValue");
			
			ChargeList = getsubscriptionchargelistCall.getJsonObject().getAsJsonObject("data").getAsJsonArray("subscriptionChargeList").get(1).getAsJsonObject();
			Logger.verifyEquals(1,ChargeList.get("funcPackageId").getAsInt(),"验证funcPackageId");
			Logger.verifyEquals(mchId,ChargeList.get("mchId").getAsInt(),"验证mchId");
			Logger.verifyEquals(0,ChargeList.get("funcType").getAsInt(),"验证funcType");
			Logger.verifyEquals("直播",ChargeList.get("funcTypeValue").getAsString(),"验证funcTypeValue");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}